﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
using System.Collections;


namespace WebVideo.Areas.Admin.Models
{
    public class FAQModel
    {
        public int Id { get; set; }

        [Required(ErrorMessage = "Tiêu đề không được rỗng")]
        public string Title { get; set; }

        [Required(ErrorMessage = "Nội dung không được để trống")]
        public string Des { get; set; }

        public DateTime? Date { get; set; }


        public static IEnumerable<EntityFAQ> Index()
        {
            dbVideoDataContext db = new dbVideoDataContext();
            var query = from p in db.EntityFAQs
                        select p;
            return query.ToList();
        }
        public static void Insert(FAQModel FAQ)
        {
            dbVideoDataContext db = new dbVideoDataContext();
            EntityFAQ faq = new EntityFAQ();
            faq.Title = FAQ.Title;
            faq.Des = FAQ.Des;
            faq.Date = DateTime.Now;
            db.EntityFAQs.InsertOnSubmit(faq);
            db.SubmitChanges();
        }

        public static FAQModel LayModel(int IdFAQ)
        {
            FAQModel Faq = new FAQModel();


            dbVideoDataContext db = new dbVideoDataContext();

            EntityFAQ tnew = db.EntityFAQs.Where(p => p.Id == IdFAQ).Single();

            Faq.Title = tnew.Title;
            Faq.Id = tnew.Id;
            Faq.Des= tnew.Des;


            return Faq;

        }
        public static void Edit(FAQModel FAQ)
        {
            dbVideoDataContext db = new dbVideoDataContext();
            EntityFAQ  Faq = db.EntityFAQs.Where(p => p.Id == FAQ.Id).Single();
            Faq.Title = FAQ.Title;
            Faq.Des = FAQ.Des;  
            db.SubmitChanges();

        }
        public static void Delete(int Id)
        {
            dbVideoDataContext db = new dbVideoDataContext();

            EntityFAQ faq = db.EntityFAQs.Where(p => p.Id == Id).Single();
            db.EntityFAQs.DeleteOnSubmit(faq);
            db.SubmitChanges();
        }
    }
}